app.register.controller("BullbearLeverincomeCtrl", ["$rootScope", "$scope", "$location", "$timeout", "$window", "ToastMessage", "SecurityService", "StockService", "$q", function($rootScope, $scope, $location, $timeout, $window, ToastMessage, SecurityService, StockService, $q) {
    function loadBullBearData() {
        return $q.all([funs.getBullBearHoldToday()])
    }
    function autoReload() {
        return isIn ? (null  != autoTimer && (autoTimer = clearTimeout(autoTimer),
        autoTimer = null ),
        void (autoTimer = setTimeout(function() {
            loadBullBearData()["finally"](autoReload)
        }, 4e3))) : !1
    }
    var isIn = !0
      , qAll = function(sName) {
        return document.querySelectorAll(sName)
    }
      , oLiTab = {
        index: 0,
        last: 0,
        aBtn: qAll(".LI_btn_con button"),
        aCon: qAll(".LI_list_con>div")
    };
    $scope.getZf = function(p) {
        return 0 == p ? "0.00%" : p ? p > 0 ? "+" + p.toFixed(2) + "%" : p.toFixed(2) + "%" : "-"
    }
    ,
    $scope.getDerict = function(num) {
        return num ? num > 0 ? "+" : "-" : "+"
    }
    ,
    $scope.getZs = function(p) {
        return 0 == p ? "0" : p ? (p += "",
        -1 == p.lastIndexOf(".") ? p : p.substring(0, p.lastIndexOf("."))) : "-"
    }
    ,
    $scope.bullBearRankInfo = function() {
        $location.url("/bullbear/leverprofitrank")
    }
    ,
    $scope.getFs = function(p) {
        return 0 == p ? "00" : p ? (p = p.toFixed(2) + "",
        -1 == p.lastIndexOf(".") ? "00" : p.substring(p.lastIndexOf(".") + 1, p.length)) : "-"
    }
    ,
    $scope.bullBear = function(p) {
        $location.url("/bullbear/levertrade?serial=" + p.serial)
    }
    ,
    $scope.getBullBearTodayList = function() {
        funs.getBullBearHoldToday(),
        oLiTab.aBtn[1].classList.remove("active"),
        oLiTab.aCon[1].classList.remove("active"),
        oLiTab.aBtn[0].classList.add("active"),
        oLiTab.aCon[0].classList.add("active")
    }
    ,
    $scope.getBullBearHisList = function() {
        funs.getBullBearHoldHis(),
        oLiTab.aBtn[0].classList.remove("active"),
        oLiTab.aCon[0].classList.remove("active"),
        oLiTab.aBtn[1].classList.add("active"),
        oLiTab.aCon[1].classList.add("active")
    }
    ;
    var funs = {
        pageLoad: function() {
            funs.getBullBearHoldToday()
        },
        getBullBearHoldToday: function() {
            var bbtPromise = StockService.bullBearHoldToday();
            return bbtPromise.success(function(data) {
                data && data.success && data.result && ($scope.todayCount = data.result.todayCount,
                $scope.todayProfitCount = data.result.todayProfitCount,
                $scope.todayProfit = data.result.todayProfit,
                data.result.itemList && ($scope.bullBearTodayList = data.result.itemList.list))
            }),
            bbtPromise
        },
        getBullBearHoldHis: function() {
            StockService.bullBearHoldHis().success(function(data) {
                if (data && data.success && data.result) {
                    $scope.histCount = data.result.histCount,
                    $scope.histProfitCount = data.result.histProfitCount,
                    $scope.histProfit = data.result.histProfit,
                    data.result.itemList && ($scope.bullBearHisList = data.result.itemList.list);
                    var dayMap = {};
                    $($scope.bullBearHisList).each(function(k, v) {
                        if (null  == dayMap[v.createTime]) {
                            var list = [];
                            list.push(v),
                            dayMap[v.createTime] = list
                        } else
                            list = dayMap[v.createTime],
                            list.push(v),
                            dayMap[v.createTime] = list
                    }),
                    $scope.todayList = [];
                    for (var key in dayMap)
                        $scope.todayList.push(dayMap[key])
                }
            })
        }
    };
    funs.pageLoad();
    var autoTimer = null ;
    autoReload(),
    $scope.$on("$destroy", function() {
        isIn = !1,
        clearTimeout(autoTimer)
    })
}
]);
